{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
    <form class="layui-form gg-form-bar border-t border-x">
        <div class="layui-input-inline" style="width: 160px;margin-right: 20px;">
            <input type="text" name="teacher" placeholder="教师名" class="layui-input" autocomplete="off" required/>
        </div>
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">搜索</button>
    </form>
    <table class="layui-hide" id="list" lay-filter="list"></table>
</div>

<script type="text/html" id="status">
    <i class="layui-icon {{#  if(d.status == 1){ }}layui-icon-ok{{#  } else { }}layui-icon-close{{#  } }}"></i>
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <span class="layui-btn layui-btn-normal layui-btn-sm add-data">+ 添加数据</span>
    </div>
</script>
<script type="text/html" id="barDemo">
    <div class="layui-btn-group">
        <!--<span class="layui-btn layui-btn-xs layui-btn-normal" lay-event="view">详情</span>-->
        <span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span>
        <span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span>
    </div>
</script>

{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];

    function gouguInit() {
        var table = layui.table, tool = layui.tool, form = layui.form;
        layui.pageTable = table.render({
            elem: '#list',
            title: '数据列表',
            toolbar: '#toolbarDemo',
            url: '/admin/data/index', //数据接口
            page: true, //开启分页
            limit: 20,
            cols: [
                [{
                    field: 'id',
                    hide: true
                }, {
                    field: 'kind',
                    title: '表类型',
                    align: 'center',
                    width: 120
                }, {
                    field: 'date',
                    title: '日期',
                    align: 'center',
                    width: 120
                }, {
                    field: 'op',
                    title: '文印类型',
                    align: 'center',
                    width: 120
                }, {
                    field: 'paper',
                    title: '纸型',
                    align: 'center',
                    width: 80
                }, {
                    field: 'double',
                    title: '单/双',
                    align: 'center',
                    width: 80
                }, {
                    field: 'amount',
                    title: '数量',
                    align: 'center',
                    width: 60
                }, {
                    field: 'content',
                    title: '内容',
                    align: 'center',
                    width: 260
                }, {
                    field: 'user',
                    title: '送印人',
                    align: 'center',
                    width: 130
                }, {
                    field: 'right',
                    fixed: 'right',
                    title: '操作',
                    toolbar: '#barDemo',
                    width: 132,
                    align: 'center'
                }]
            ]
        });
        //表头工具栏事件
        $('body').on('click', '.add-data', function () {
            tool.side("/admin/data/add");
        });
        //监听行工具事件
        table.on('tool(list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'view') {
                tool.side('/admin/data/view?id=' + data.id);
            } else if (obj.event === 'edit') {
                tool.side('/admin/data/add?id=' + data.id);
            } else if (obj.event === 'del') {
                layer.confirm('您确定要删除吗', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            obj.del();
                        }
                    };
                    tool.delete("/admin/data/delete", {id: data.id}, callback);
                    layer.close(index);
                });
            }
        });

        //监听搜索提交
        form.on('submit(webform)', function (data) {
            layui.pageTable.reload({
                where: {
                    teacher: data.field.teacher
                },
                page: {
                    curr: 1
                }
            });
            return false;
        });
    }
</script>
{/block}
<!-- /脚本 -->